<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" title="任务详情" size="lg" hide-footer scrollable no-close-on-backdrop>
        <div class="d-block text-center">
            <!--begin::div-->
            <div class="m-form m-form--fit m-form--label-align-left m-form--group-seperator-dashed">
                <div class="m-portlet__body">
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">流程名称</label>
                        <div class="col-lg-6">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.processTitle">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">产&nbsp;品&nbsp;&nbsp;线</label>
                        <div class="col-lg-6">
                            <input class="form-control" type="text" disabled maxlength="50" v-model="lcTaskForm.productName">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">产&nbsp;品&nbsp;&nbsp;组</label>
                        <div class="col-lg-6">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.groupName">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">租&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;户</label>
                        <div class="col-lg-6">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.tenantId">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">版&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本</label>
                        <div class="col-lg-2">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.version">
                        </div>
                    </div>

                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">任务名称</label>
                        <div class="col-lg-4">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.name">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">任务编号</label>
                        <div class="col-lg-4">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.taskId">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">开始时间</label>
                        <div class="col-lg-4">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.createTime">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">结束时间</label>
                        <div class="col-lg-4">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.endTime">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">耗&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时</label>
                        <div class="col-lg-4">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.durationInMillis">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">经&nbsp;办&nbsp;&nbsp;人</label>
                        <div class="col-lg-2">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.assignee">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">发&nbsp;起&nbsp;&nbsp;人</label>
                        <div class="col-lg-2">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.owner">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">流程定义</label>
                        <div class="col-lg-4">
                            <input class="form-control" type="text" disabled v-model="lcTaskForm.processDefinitionId">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
        </template>
    </b-modal>
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js";
import { handleNotify, handleAlert, handleConfirm, showWating, closeWating,dateformat } from "@/core/util/jehcUtil.js";
export default {
    data() {
        return {
            lcTaskForm: {
                processTitle: "",
                productName: "",
                groupName: "",
                tenantId: "",
                version: "",
                name: "",
                groupName: "",
                taskId: "",
                createTime: "",
                endTime: "",
                durationInMillis: "",
                assignee: "",
                owner: "",
                processDefinitionId: "",
            }
        }
    },
    components: {

    },
    watch: {
    },
    mounted() {

    },
    methods: {
        showModal(id) {
            this.restForm();
            this.$refs['my-modal'].show();
            this.getDetail(id);
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        restForm() {
            //重置
            Object.assign(this.$data.lcTaskForm, this.$options.data().lcTaskForm);
        },
        getDetail(id) {
            apiUtil.get(process.env.VUE_APP_WORKFLOW_API + "/lcTaskHis/get/" + id).then(({ data }) => {
                this.lcTaskForm = data.data;
                this.lcTaskForm.durationInMillis = this.formateDhms(this.lcTaskForm.durationInMillis);
                this.lcTaskForm.createTime = this.formatterTime(this.lcTaskForm.createTime)
                this.lcTaskForm.endTime = this.formatterTime(this.lcTaskForm.endTime)
            });
        },
        formateDhms(timestamp){
            if (timestamp) {
                timestamp = timestamp/1000;
                var result = '';
                if (timestamp >= 86400) {
                    var days = Math.floor(timestamp / 86400);
                    timestamp = timestamp % 86400;
                    result = days  + ' 天';
                    if (timestamp > 0) {
                        result += ' ';
                    }
                }
                if (timestamp >= 3600) {
                    var hours = Math.floor(timestamp / 3600);
                    timestamp = timestamp % 3600;
                    result += hours + ' 小时';
                    if (timestamp > 0) {
                        result += ' ';
                    }
                }
                if (timestamp >= 60) {
                    var minutes = Math.floor(timestamp / 60);
                    timestamp = timestamp % 60;
                    result += minutes + ' 分钟';
                    if (timestamp > 0) {
                        result += ' ';
                    }
                }
                result += parseInt(timestamp) + ' 秒';
                return result;
            }
            return "";
        },
        formatterTime(time){
            return dateformat(time);
        },
    }
}
</script>